from core import *


class CultureEffect(Effect):
    pass


class Culturable(Ability):
    @property
    def culture_level(self):
        return len(list(self.effects.all(CultureEffect)))


class CultureWalker(Walker):
    duration =_ (None)
    radius   =_ (None)
    spreads  =_ (None)
    
    freshman = Attribute(initial = False, writable = True)
    
    def on_arrival(self):
        if self.freshman:
            self.target.left = self.duration
        
        super(CultureWalker, self).on_arrival()
    
    def day(self, day, month, year):
        for house in self.tile.nearby(Culturable, radius = self.radius):
            house.set_effect(self.spreads)


class CultureBuilding(StaffedBuilding):
    left = Attribute(initial = 0, writable = True)
    
    @property
    def ready(self):
        return (self.left > 0)
    
    def day(self, day, month, year):
        if self.left > 0:
            self.left -= 1
        
        super(CultureBuilding, self).day(day, month, year)


class CultureSourceBuilding(StaffedBuilding):
    supplies =_ (None)
    
    @property
    def walker_attributes(self):
        return {'target'  : self.city.random(self.supplies),
                'freshman': True}
    
    @property
    def ready(self):
        return self.city.random(self.supplies) is not None
